<template>
    <div class="login">
        <div>登录
        </div>
        <div>
        手机号:<el-input v-model="phone" placeholder="请输入内容"></el-input>


        </div>
        <div class="password">
        密码:<el-input type='password'  v-model="password" placeholder="请输入内容"></el-input>

        </div>
        <el-button @click="logonhandel">登录</el-button>
        <el-button @click="logonhandelno">退出</el-button>
    </div>
</template>

<script>
import http from '@/http/http.js'

export default {

    data() {
        return {
            phone:'',
            password:'',
            userid:'',
            isshow:false
        }
    },
    methods: {

        logonhandelno(){
            this.phone = ''
            this.password = ''
            this.$emit('isshowzi',this.isshow)
        },
        logonhandel(){
            http({
            url:'/login/cellphone',
            params:{
                phone:this.phone,
                password:this.password
                }
            }
            ).then(res=>{
            // this.userid = res.data.profile.userId
            // if(res.data)
            if(res.data.code === 400){
                this.$message.error('请输入正确的账号密码');
            }else if(res.data.code === 502){
                this.$message.error('自己密码都记不得？');
            }else if(res.data.code === 200){
                // console.log(res.data.profile)
                this.$message({
                message: '登录成功',
                type: 'success'
                });
                this.phone = ''
                this.password = ''
                this.$emit('isshowzi',this.isshow,res.data.profile)

                this.$store.commit('islogin')
                window.localStorage.setItem('cookie',res.data.cookie)
                window.localStorage.setItem('userId',res.data.profile.userId)
            }
            

            // console.log(res.data.code)
            // window.localStorage.setItem('token',res.data.token)
            // window.localStorage.setItem('cookie',res.data.cookie)
            // window.localStorage.setItem('userId',res.data.profile.userId)



                    // http({
                    // url:'/user/detail',
                    // params:{
                    //     uid:this.userid
                    // }
                    // }
                    // ).then(res=>{
                    //     console.log(res) 
                    // })
            })
     
        }
    },
    mounted() {
        
    },
}
</script>

<style lang="less" scoped>
.login{
    width: 300px;
    height: 200px;
    text-align: center;
    border: 1px solid #000;
    background-color: pink;
}
.password{
    margin-bottom: 5px;
}
</style>